import 'dart:convert';
import 'dart:io';
import 'dart:ui';

import 'package:cached_network_image/cached_network_image.dart';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter_aygsh/liz_home/goods/ShareGoodsPic.dart';
import 'package:flutter_aygsh/liz_mine/order/LocalNavWebWidget.dart';
import 'package:flutter_aygsh/liz_mine/order/OrderComment.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import 'package:provider/provider.dart';

import './gallery_entity.dart';
import '../../base/Constant.dart';
import '../../base/application.dart';
import '../../entity/goods_list_entity.dart';
import '../../event/LoginEvent.dart';
import '../../http/Api.dart';
import '../../http/HttpUtil.dart';
import '../../liz_car/MyShopCar.dart';
import '../../shopper/BecomeShopper.dart';
import '../../util/AppSaveInfoUtil.dart';
import '../../util/SignUtil.dart';
import '../../util/Toast.dart';
import '../goods/sku_dialog.dart';
import 'BrandDetail.dart';
import 'BuyGoods.dart';
import 'CommentList.dart';
import 'GoodsDetailsModel.dart';
import 'SkuProvider.dart';

class GoodsDetailPage extends StatefulWidget {
  String goods_id = "";
  String img;
  int type = 0; //默认非抢购
  String id = "0";
  String start_time = "",
      end_time = "",
      limit_num = "",
      all_num = "",
      sale_num = "";
  GoodsDetailPage(
      {Key key,
      @required this.goods_id,
      this.img,
      this.type,
      this.id,
      this.all_num,
      this.end_time,
      this.limit_num,
      this.sale_num,
      this.start_time})
      : super(key: key);

  _GoodsDetailPageState createState() => _GoodsDetailPageState();
}

class _GoodsDetailPageState extends State<GoodsDetailPage>
    with WidgetsBindingObserver {
  double appBarAlpha = 0;
  SkuProvider skuProvider;
  Object price = "";
  Object old_price = "";
  String goods_name = "", lv_price = "";
  String html = "";
  List<GalleryModel> gallery = List();
  bool hasSku = false;
  int count = 0;
  int goods_num = 1;
  String token = "";
  String lable = '';
  Map<String, dynamic> skuMap = {"skus": [], "goods": []};
  GoodsDetailsModel goodsDetailsModel;
  String _day1 = '';
  String _hour1 = '';
  String _minute1 = '';
  String _second1 = '';
  List comments = []; //评论列表
  List<GoodsModelData> shopData = [];
  String brand_name = '店铺名称';
  String brand_id = '0';
  String logo = '';
  String is_collect = 'N';
  bool isVip = true;
  String save_money = '';
  String postage = '0';

  @override
  Widget build(BuildContext context) {
    ScreenUtil.instance = ScreenUtil(width: 750, height: 1334)..init(context);

    return new Scaffold(
      appBar: new AppBar(
        title: Text('商品详情',
            style: TextStyle(
                fontSize: ScreenUtil.getInstance().setSp(BIG_FONT_SIZE),
                color: Colors.black)),
        backgroundColor: Colors.white,
        brightness: Brightness.light,
        centerTitle: true,
        iconTheme: new IconThemeData(color: Colors.black),
        elevation: 0.5,
        actions: <Widget>[
          GestureDetector(
            child: Container(
              child: Icon(
                Icons.share,
                color: black,
                size: 25,
              ),
              padding: EdgeInsets.only(right: 14),
            ),
            onTap: () {
              Navigator.of(context)
                  .push(new MaterialPageRoute(builder: (context) {
                return new ShareGoodsPicPage(
                  goods_id: widget.goods_id,
                  // pics: temp,
                  goods_name: goods_name,
                  price: price,
                  old_price: old_price,
                  img: gallery[0].img,
                );
              }));
            },
            behavior: HitTestBehavior.opaque,
          )
        ],
      ),
      body: ChangeNotifierProvider.value(
          value: skuProvider,
          child: Consumer<SkuProvider>(builder: (context, provider, _) {
            return new Column(
              children: <Widget>[
                Expanded(
                  child: Container(
                      child: new Scrollbar(
                    child: new SingleChildScrollView(
                      child: new Container(
                        child: new Column(
                          children: <Widget>[
                            Stack(
                              children: <Widget>[
                                Container(
                                  height: MediaQuery.of(context).size.width,
                                  child: gallery.length == 0
                                      ? Center()
                                      : Swiper(
                                          containerHeight:
                                              MediaQuery.of(context).size.width,
                                          itemHeight:
                                              MediaQuery.of(context).size.width,
                                          itemBuilder: (BuildContext context,
                                              int index) {
                                            return new ClipRRect(
                                              child: gallery[index].img == ""
                                                  ? Image.asset(
                                                      'images/pic_default.png',
                                                      fit: BoxFit.fill,
                                                    )
                                                  : gallery[index]
                                                          .img
                                                          .contains("upload")
                                                      ? Image.network(
                                                          Api.BaseUrl +
                                                              gallery[index]
                                                                  .img
                                                                  .replaceAll(
                                                                      '\\',
                                                                      '/'),
                                                          fit: BoxFit.fill,
                                                        )
                                                      : Image.network(
                                                          Api.ImgBaseUrl +
                                                              gallery[index]
                                                                  .img
                                                                  .replaceAll(
                                                                      '\\',
                                                                      '/'),
                                                          fit: BoxFit.fill,
                                                        ),
                                              borderRadius:
                                                  BorderRadius.circular(0.0),
                                            );
                                          },
                                          itemCount: count,
                                          pagination: new SwiperPagination(
                                              builder:
                                                  DotSwiperPaginationBuilder(
                                                      color: Colors.grey,
                                                      activeColor: mainColor,
                                                      size: 7.0,
                                                      activeSize: 7.0)),
                                          scrollDirection: Axis.horizontal,
                                          autoplay: true,
                                          onTap: (index) {
                                            // Navigator.of(context)
                                            //     .push(new MaterialPageRoute(builder: (context) {
                                            //   return new HomeWebview(
                                            //     article_id: bannerData[index].img,
                                            //     title: bannerData[index].title,
                                            //   );
                                            // }));
                                          },
                                        ),
                                ),
                              ],
                            ),
                            Container(
                              alignment: Alignment.centerLeft,
                              color: white,
                              child: Padding(
                                padding: EdgeInsets.fromLTRB(10, 0, 10, 10),
                                child: Row(
                                  mainAxisAlignment: MainAxisAlignment.end,
                                  crossAxisAlignment: CrossAxisAlignment.end,
                                  children: <Widget>[
                                    Container(
                                        // height: 30,
                                        // padding: EdgeInsets.all(5),
                                        // color: black,
                                        alignment: Alignment.centerLeft,
                                        child: Text(
                                          provider.selectedSkuModel == null
                                              ? MONEY + price.toString()
                                              : MONEY +
                                                  provider
                                                      .selectedSkuModel.price
                                                      .toString(),
                                          style: TextStyle(
                                            fontSize: ScreenUtil.getInstance()
                                                .setSp(BIG_FONT_SIZE + 8),
                                            fontWeight: FontWeight.bold,
                                            color: Colors.red,
                                          ),
                                        )),
                                    // Container(
                                    //   width: 5,
                                    // ),
                                    Container(
                                        //  height: 20,
                                        padding: EdgeInsets.all(
                                            ScreenUtil.getInstance()
                                                .setWidth(8)),
                                        // color: black,
                                        alignment: Alignment.topLeft,
                                        child: Text(MONEY + old_price,
                                            style: TextStyle(
                                                fontSize: ScreenUtil
                                                        .getInstance()
                                                    .setSp(SMALL_FONT_SIZE - 2),
                                                color: Colors.grey,
                                                decoration:
                                                    TextDecoration.lineThrough,
                                                decorationColor: Colors.grey))),
                                    Container(
                                      width: 5,
                                    ),
                                    Expanded(
                                      child: Container(
                                        margin: EdgeInsets.only(top: 10),
                                        child: GridView.builder(
                                          shrinkWrap: true,
                                          padding: EdgeInsets.only(top: 0),
                                          physics:
                                              new NeverScrollableScrollPhysics(),
                                          gridDelegate:
                                              SliverGridDelegateWithFixedCrossAxisCount(
                                                  crossAxisCount: 5,
                                                  mainAxisSpacing:
                                                      ScreenUtil.getInstance()
                                                          .setHeight(DP_10),
                                                  crossAxisSpacing:
                                                      ScreenUtil.getInstance()
                                                          .setHeight(DP_10),
                                                  childAspectRatio: 2.7),
                                          itemBuilder: (BuildContext context,
                                              int index1) {
                                            List m = lable.split(';');
                                            return Container(
                                              decoration: BoxDecoration(
                                                  border: Border.all(
                                                      color: Colors.red),
                                                  // color: Color.fromRGBO(
                                                  //     253, 232, 227, 1),
                                                  borderRadius:
                                                      BorderRadius.circular(3)),
                                              alignment: Alignment.center,
                                              child: Text(
                                                m[index1],
                                                style: TextStyle(
                                                    color: Colors.red,
                                                    fontSize:
                                                        ScreenUtil.getInstance()
                                                            .setSp(21),
                                                    fontWeight:
                                                        FontWeight.w400),
                                              ),
                                            );
                                          },
                                          itemCount: lable == null ||
                                                  lable == 'null' ||
                                                  lable == ''
                                              ? 0
                                              : lable.split(';').length,
                                        ),
                                      ),
                                    )
                                  ],
                                ),
                              ),
                            ),
                            Container(
                                color: white,
                                child: GestureDetector(
                                  onTap: () {
                                    if ((APPLIC.userInfoMap == null ||
                                        APPLIC.userInfoMap['user_msg']
                                                ['group_id'] ==
                                            1||
                                        APPLIC.userInfoMap['user_msg']
                                                ['group_id'] ==
                                            2)) {
                                      Navigator.of(context).push(
                                          new MaterialPageRoute(
                                              builder: (context) {
                                        return new BecomeShopperPage();
                                      }));
                                    }
                                  },
                                  child: Container(
                                    color: black,
                                    height:
                                        ScreenUtil.getInstance().setHeight(60),
                                    margin: EdgeInsets.all(10),
                                    alignment: Alignment.center,
                                    child: Text(
                                      (APPLIC.userInfoMap == null ||
                                              APPLIC.userInfoMap['user_msg']
                                                      ['group_id'] ==
                                                  1)
                                          ? '成为店主本次可以为您节省¥' + save_money
                                          : "尊贵的" +
                                              APPLIC.userInfoMap['user_msg']
                                                  ['group_name'] +
                                              "，本次购物可以为您节省" +
                                              save_money +
                                              "元",
                                      style: TextStyle(
                                          color:
                                              Color.fromRGBO(235, 223, 181, 1),
                                          fontSize: ScreenUtil.getInstance()
                                              .setSp(NORMAL_FONT_SIZE - 3),
                                          fontWeight: FontWeight.w300),
                                    ),
                                  ),
                                )),
                            Container(
                              color: white,
                              height: ScreenUtil.getInstance().setHeight(40),
                              // margin: EdgeInsets.all(10),
                              alignment: Alignment.center,
                              child: Text(
                                '• 正品保障 • 超低折扣 • 售后保障',
                                style: TextStyle(
                                    color: Colors.black54,
                                    fontSize: ScreenUtil.getInstance()
                                        .setSp(NINIEST_FONT_SIZE + 2),
                                    fontWeight: FontWeight.w300),
                              ),
                            ),
                            Container(
                              color: white,
                              alignment: Alignment.centerLeft,
                              child: Padding(
                                padding: EdgeInsets.fromLTRB(10, 10, 10, 5),
                                child: Text(goods_name,
                                    style: TextStyle(
                                      fontSize: ScreenUtil.getInstance()
                                          .setSp(BIG_FONT_SIZE),
                                      fontWeight: FontWeight.w500,
                                      color: black,
                                    )),
                              ),
                            ),
                            Container(
                              height: 1,
                              color: divideColor,
                            ),
                            hasSku
                                ? Container()
                                : Container(
                                    height: 50,
                                    padding: EdgeInsets.all(10),
                                    color: white,
                                    child: new GestureDetector(
                                      behavior: HitTestBehavior.opaque,
                                      onTap: () {
                                        showGoodsAttributes(context);
                                      },
                                      child: new Row(
                                        children: <Widget>[
                                          Padding(
                                            padding: EdgeInsets.fromLTRB(
                                                0, 0, 15, 0),
                                            child: Text("选择",
                                                style: TextStyle(
                                                  color: black,
                                                  fontSize:
                                                      ScreenUtil.getInstance()
                                                          .setSp(
                                                              SMALL_FONT_SIZE),
                                                  fontWeight: FontWeight.w700,
                                                )),
                                          ),
                                          Expanded(
                                            child: Text(
                                                provider.selectedSku ?? '',
                                                style: TextStyle(
                                                    color: black_99,
                                                    fontSize: ScreenUtil
                                                            .getInstance()
                                                        .setSp(SMALL_FONT_SIZE),
                                                    fontWeight:
                                                        FontWeight.w500)),
                                          ),
                                          Icon(
                                            Icons.arrow_forward_ios,
                                            size: 15,
                                          )
                                        ],
                                      ),
                                    ),
                                  ),
                            Container(
                              height: 1,
                              color: divideColor,
                            ),
                            comments.length > 0
                                ? Container(
                                    //横向滑动列表
                                    color: Colors.white,
                                    margin: EdgeInsets.fromLTRB(
                                      0,
                                      0,
                                      0,
                                      0,
                                    ),
                                    height: ScreenUtil.getInstance()
                                        .setHeight(DP_400),
                                    child: Column(
                                      children: <Widget>[
                                        Row(
                                          children: <Widget>[
                                            Expanded(
                                              flex: 1,
                                              child: Container(
                                                margin: EdgeInsets.fromLTRB(
                                                    ScreenUtil.getInstance()
                                                        .setWidth(DP_30),
                                                    ScreenUtil.getInstance()
                                                        .setHeight(DP_20),
                                                    0,
                                                    0),
                                                child: Text(
                                                  '商品评价',
                                                  style: TextStyle(
                                                      fontSize: ScreenUtil
                                                              .getInstance()
                                                          .setSp(
                                                              BIG_FONT_SIZE)),
                                                ),
                                              ),
                                            ),
                                            GestureDetector(
                                              onTap: () {
                                                Navigator.of(context).push(
                                                    MaterialPageRoute(
                                                        builder: (context) {
                                                  return GoodsCommentListPage(
                                                      course_id:
                                                          widget.goods_id);
                                                }));
                                              },
                                              child: Container(
                                                  margin: EdgeInsets.fromLTRB(
                                                      ScreenUtil.getInstance()
                                                          .setWidth(DP_30),
                                                      ScreenUtil.getInstance()
                                                          .setHeight(DP_20),
                                                      ScreenUtil.getInstance()
                                                          .setWidth(DP_20),
                                                      0),
                                                  child: Text(
                                                    '更多好评>',
                                                    style: TextStyle(
                                                        color: Colors.orange,
                                                        fontSize: ScreenUtil
                                                                .getInstance()
                                                            .setSp(
                                                                SMALL_FONT_SIZE)),
                                                  )),
                                              behavior: HitTestBehavior.opaque,
                                            )
                                          ],
                                        ),
                                        Container(
                                            height: ScreenUtil.getInstance()
                                                .setHeight(DP_300),
                                            color: f0Color,
                                            child: ListView(
                                              //设置水平方向排列
                                              scrollDirection: Axis.horizontal,
                                              //添加子元素
                                              children: <Widget>[zdGrid()],
                                            ))
                                      ],
                                    ))
                                : Container(
                                    child: Text('暂无评论'),
                                  ),
                            Container(
                              height: 10,
                              color: divideColor,
                            ),
                            brand_id != '0'
                                ? GestureDetector(
                                    onTap: () {
                                      //品牌页面
                                      Navigator.of(context).push(
                                          MaterialPageRoute(builder: (context) {
                                        return BrandDetailPage(
                                            brand_id: brand_id);
                                      }));
                                    },
                                    child: Container(
                                      padding: EdgeInsets.fromLTRB(kMargin20,
                                          kMargin20, kMargin20, kMargin20),
                                      color: Colors.white,
                                      child: Row(
                                        children: <Widget>[
                                          Container(
                                              margin: EdgeInsets.fromLTRB(
                                                  0, 0, kMargin5, 0),
                                              width: kMargin140,
                                              height: kMargin140,
                                              child: ClipRRect(
                                                borderRadius:
                                                    BorderRadius.circular(
                                                        kMargin15),
                                                child: logo == ''
                                                    ? Image.asset(
                                                        'images/pic_default.png')
                                                    : Image.network(
                                                        Api.BaseUrl +
                                                            'public/upload/' +
                                                            logo.replaceAll(
                                                                '\\', '/'),
                                                      ),
                                              )),
                                          Expanded(
                                            child: Text(brand_name),
                                          ),
                                          Container(
                                            alignment: Alignment.centerRight,
                                            margin: EdgeInsets.fromLTRB(
                                                0, 0, kMargin5, 0),
                                            width: kMargin140,
                                            height: kMargin140,
                                            child: Image.asset(
                                                'images/shangpin_more.png'),
                                          ),
                                        ],
                                      ),
                                    ))
                                : Container(),
                            Container(
                              height: 10,
                              color: divideColor,
                            ),
                            shopData.length > 0
                                ? Container(
                                    color: Colors.white,
                                    child: Column(children: <Widget>[
                                      // Expanded(
                                      //   flex: 1,
                                      //   child:
                                      Container(
                                        alignment: Alignment.centerLeft,
                                        margin: EdgeInsets.fromLTRB(
                                            ScreenUtil.getInstance()
                                                .setWidth(DP_30),
                                            ScreenUtil.getInstance()
                                                .setHeight(DP_20),
                                            0,
                                            0),
                                        child: Text(
                                          '看了这件商品的人也看了',
                                          style: TextStyle(
                                              fontSize: ScreenUtil.getInstance()
                                                  .setSp(BIG_FONT_SIZE)),
                                        ),
                                      ),
                                      GridView.builder(
                                        physics:
                                            const NeverScrollableScrollPhysics(),
                                        shrinkWrap: true,
                                        gridDelegate:
                                            SliverGridDelegateWithFixedCrossAxisCount(
                                                crossAxisCount: 3,
                                                mainAxisSpacing: 10.0,
                                                crossAxisSpacing: 10.0,
                                                childAspectRatio: 0.64),
                                        itemBuilder: (context, index) {
                                          return getItemContainer(
                                              context, index);
                                        },
                                        itemCount: shopData == null
                                            ? 0
                                            : shopData.length,
                                      ),
                                      // ),
                                    ]))
                                : Container(),
                            new Row(
                              children: <Widget>[
                                Expanded(
                                  child: Container(
                                    margin: EdgeInsets.fromLTRB(
                                        ScreenUtil.getInstance().setWidth(150),
                                        0,
                                        20,
                                        0),
                                    height: 1,
                                    color: Colors.grey,
                                  ),
                                ),
                                Text(
                                  "商品详情",
                                  textAlign: TextAlign.right,
                                  style: new TextStyle(
                                      color: Colors.grey, fontSize: 14),
                                ),
                                Expanded(
                                  child: Container(
                                    margin: EdgeInsets.fromLTRB(
                                        20,
                                        0,
                                        ScreenUtil.getInstance().setWidth(150),
                                        0),
                                    height: 1,
                                    color: Colors.grey,
                                  ),
                                ),
                              ],
                            ),
                            Container(
                              color: white,
                              padding: EdgeInsets.all(10),
                              margin: EdgeInsets.fromLTRB(0, 10, 0, 0),
                              child: Html(data: html),
                            )
                          ],
                        ),
                      ),
                    ),
                  )),
                ),
                Container(
                  height: 1,
                  width: ScreenUtil.getInstance().setWidth(750),
                  color: f0Color,
                ),
                Container(
                  color: white,
                  padding: EdgeInsets.fromLTRB(
                      ScreenUtil.getInstance().setWidth(10),
                      5,
                      ScreenUtil.getInstance().setWidth(20),
                      5),
                  child: Row(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      Expanded(
                          flex: 1,
                          child: GestureDetector(
                            onTap: () {
                              if(APPLIC.userInfoMap==null){
                                return ;
                              }
                              if (Platform.isAndroid) {
                                Navigator.of(context).push<String>(
                                    MaterialPageRoute(builder: (context) {
                                  return new LocalNavWebWidget(
                                      "http://kf.0731app.cn/index/index/home?visiter_id=" +
                                          APPLIC.userInfoMap['user_msg']
                                                  ['uid']
                                              .toString() +
                                          "&visiter_name=" +
                                          APPLIC.userInfoMap['user_msg']
                                                  ['phone']
                                              .toString() +
                                          "&avatar=&business_id=3&groupid=0&special=7",
                                      "客服");
                                })).then((value) {});
                                return;
                              }
                              Navigator.of(context).push<String>(
                                  MaterialPageRoute(builder: (context) {
                                return OrderCommentPage(
                                    url: "http://kf.0731app.cn/index/index/home?visiter_id=" +
                                        APPLIC.userInfoMap['user_msg']
                                                ['uid']
                                            .toString() +
                                        "&visiter_name=" +
                                        APPLIC.userInfoMap['user_msg']['phone']
                                            .toString() +
                                        "&avatar=&business_id=3&groupid=0&special=7");
                              })).then((value) {});
                            },
                            behavior: HitTestBehavior.opaque,
                            child: new Column(
                              children: <Widget>[
                                Padding(
                                  padding: EdgeInsets.fromLTRB(0, 0, 0, 0),
                                  child: Image.asset('images/shangpin_kefu.png',
                                      scale: 1.7),
                                ),
                                Text('客服',
                                    style: TextStyle(
                                        fontSize: ScreenUtil.getInstance()
                                            .setSp(SMALL_FONT_SIZE - 4)))
                              ],
                            ),
                          )),
                      Expanded(
                          flex: 1,
                          child: GestureDetector(
                            onTap: () {
                              is_collect == 'Y' ? cancelCollect() : collect();
                            },
                            behavior: HitTestBehavior.opaque,
                            child: new Column(
                              children: <Widget>[
                                Padding(
                                  padding: EdgeInsets.fromLTRB(0, 0, 0, 0),
                                  child: is_collect == 'Y'
                                      ? Image.asset(
                                          'images/shangpin_sshoucang.png',
                                          scale: 1.7)
                                      : Image.asset(
                                          'images/shangpin_shoucang.png',
                                          scale: 1.7),
                                ),
                                Text(is_collect == 'Y' ? "已收藏" : '收藏',
                                    style: TextStyle(
                                        fontSize: ScreenUtil.getInstance()
                                            .setSp(SMALL_FONT_SIZE - 4)))
                              ],
                            ),
                          )),
                      Expanded(
                          flex: 1,
                          child: GestureDetector(
                            onTap: () {
                              Navigator.of(context)
                                  .push(MaterialPageRoute(builder: (context) {
                                return MyShopCarPage();
                              }));
                            },
                            behavior: HitTestBehavior.opaque,
                            child: new Column(
                              children: <Widget>[
                                Padding(
                                  padding: EdgeInsets.fromLTRB(0, 0, 0, 0),
                                  child: Image.asset(
                                      'images/shangpin_gouwuche.png',
                                      scale: 1.7),
                                ),
                                Text('购物车',
                                    style: TextStyle(
                                        fontSize: ScreenUtil.getInstance()
                                            .setSp(SMALL_FONT_SIZE - 4)))
                              ],
                            ),
                          )),
                      new Container(
                        margin: EdgeInsets.fromLTRB(0, 10, 0, 10),
                        height: ScreenUtil.getInstance().setHeight(66),
                        decoration: new BoxDecoration(
                            color: Color.fromRGBO(239, 150, 128, 1),
                            borderRadius: BorderRadius.only(
                              bottomLeft: Radius.circular(20),
                              topLeft: Radius.circular(20),
                            )),
                        child: new FlatButton(
                          child: new Padding(
                            padding: EdgeInsets.all(0.0),
                            child: new Text(
                              "加入购物车",
                              style: new TextStyle(
                                  color: Colors.white,
                                  fontSize: ScreenUtil.getInstance()
                                      .setSp(NORMAL_FONT_SIZE + 2),
                                  fontWeight: FontWeight.w300),
                            ),
                          ),
                          onPressed: () {
                            print('点击加入购物车');
                            // Navigator.of(context).pop();
                            if (provider.selectedSku.contains("请选择") &&
                                hasSku == false) {
                              showGoodsAttributes(context);
                              return;
                            }
                            if (hasSku) {
                              addToCar("");
                              return;
                            }
                            List<Map> skuMap = List();
                            List<Goods> list = goodsDetailsModel.goods;
                            for (int i = 0; i < list.length; i++) {
                              Map goodsSku = new Map();
                              goodsSku['attribute_id'] = list[i].attribute_id;
                              goodsSku['value'] = skuProvider
                                  .selectedSkuModel.sku
                                  .split(";")[i];
                              skuMap.add(goodsSku);
                            }
                            addToCar(json.encode(skuMap).toString());
                          },
                        ),
                      ),
                      // Container(
                      //   width: 10,
                      // ),
                      new Container(
                        height: ScreenUtil.getInstance().setHeight(66),
                        decoration: new BoxDecoration(
                            color: mainColor,
                            borderRadius: BorderRadius.only(
                              bottomRight: Radius.circular(20),
                              topRight: Radius.circular(20),
                            )),
                        child: new FlatButton(
                          child: new Padding(
                            padding: EdgeInsets.all(0.0),
                            child: new Text(
                              "立即购买 ",
                              style: new TextStyle(
                                  color: Colors.white,
                                  fontSize: ScreenUtil.getInstance()
                                      .setSp(NORMAL_FONT_SIZE + 2),
                                  fontWeight: FontWeight.w300),
                            ),
                          ),
                          onPressed: () {
                            if (provider.selectedSku.contains("请选择") &&
                                hasSku == false) {
                              showGoodsAttributes(context);
                            } else {
                              if (hasSku) {
                                Navigator.of(context)
                                    .push(MaterialPageRoute(builder: (context) {
                                  return BuyGoodsPage(
                                    old: '',
                                    postage: postage.toString(),
                                    save_money: save_money,
                                    goods_num: goods_num.toString(),
                                    goods_id: widget.goods_id,
                                    goods_name: goods_name,
                                    goods_img: gallery[0].img,
                                    type: widget.type.toString(),
                                    id: widget.id,
                                    price: price.toString(),
                                    skuJson: "",
                                    skuInfo: "无配置",
                                  );
                                }));
                                return;
                              }
                              List<Map> skuMap = List();
                              List<Goods> list = goodsDetailsModel.goods;
                              for (int i = 0; i < list.length; i++) {
                                Map goodsSku = new Map();
                                goodsSku['attribute_id'] = list[i].attribute_id;
                                goodsSku['value'] =
                                    provider.selectedSkuModel.sku.split(";")[i];
                                skuMap.add(goodsSku);
                              }
                              // print(json.encode(skuMap).toString());
                              Navigator.of(context)
                                  .push(MaterialPageRoute(builder: (context) {
                                return BuyGoodsPage(
                                  old: '',
                                  goods_num: goods_num.toString(),
                                  type: widget.type.toString(),
                                  save_money: save_money,
                                  goods_id: widget.goods_id,
                                  goods_name: goods_name,
                                  id: widget.id,
                                  postage: "0",
                                  goods_img: provider.selectedSkuModel.img,
                                  price: provider.selectedSkuModel.price
                                      .toString(),
                                  skuJson: json.encode(skuMap).toString(),
                                  skuInfo: provider.selectedSkuModel.sku,
                                );
                              }));
                            }
                          },
                        ),
                      )
                    ],
                  ),
                )
              ],
            );
          })),
    );
  }

  getItemContainer(BuildContext context, int index) {
    var price = RichText(
        textAlign: TextAlign.left,
        text: TextSpan(style: TextStyle(color: Colors.red), children: [
          TextSpan(
              text: '¥',
              style: TextStyle(
                  fontSize: ScreenUtil.getInstance().setSp(NINIEST_FONT_SIZE))),
          TextSpan(
              // text: shopData[index].zk_final_price,
              text: shopData[index].price,
              style: TextStyle(
                  fontSize: ScreenUtil.getInstance().setSp(SMALL_FONT_SIZE))),
          TextSpan(
            // text: shopData[index].reserve_price,
            text: shopData[index].old_price,
            style: TextStyle(
                fontSize: ScreenUtil.getInstance().setSp(MINI_FONT_SIZE),
                color: Colors.grey,
                decoration: TextDecoration.lineThrough,
                decorationColor: Colors.grey),
          ),
        ]),
        maxLines: 1,
        overflow: TextOverflow.ellipsis,
        textDirection: TextDirection.ltr);
    return new GestureDetector(
        onTap: () {
          //处理点击事件
          GoodsModelData model = shopData[index];

          Navigator.of(context).push(new MaterialPageRoute(builder: (context) {
            return GoodsDetailPage(
              goods_id: model.goods_id,
              img: model.img,
            );
          }));
        },
        child: Container(
            color: Colors.white,
            margin: EdgeInsets.fromLTRB(kMargin10, 0, kMargin10, 0),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                shopData[index].img == ''
                    ? Image.asset('images/pic_default.png')
                    : Image.network(
                        Api.BaseUrl +
                            'public/upload/' +
                            shopData[index].img.replaceAll('\\', '/'),
                        width: (ScreenUtil.getInstance().setWidth(750) -
                                kMargin20) /
                            3,
                        height: (ScreenUtil.getInstance().setWidth(750) -
                                kMargin20) /
                            3,
                      ),
                Text(shopData[index].goods_name,
                    maxLines: 2,
                    style: TextStyle(
                        fontSize:
                            ScreenUtil.getInstance().setSp(SMALL_FONT_SIZE))),
                Container(
                  margin: EdgeInsets.all(kMargin5),
                  child: price,
                ),
              ],
            )));
  }

  Widget zdGrid() {
    //商品评论
    List<Widget> tiles = []; //先建一个数组用于存放循环生成的widget
    Widget content; //单独一个widget组件，用于返回需要生成的内容widget
    for (var item in comments) {
      tiles.add(GestureDetector(
          onTap: () {},
          child: Container(
              margin: EdgeInsets.fromLTRB(kMargin10, 0, kMargin10, 0),
              height: ScreenUtil.getInstance().setHeight(DP_280),
              width: item['have_img'].toString() == 'Y'
                  ? ScreenUtil.getInstance().setWidth(DP_600)
                  : ScreenUtil.getInstance().setWidth(DP_400),
              padding: EdgeInsets.all(ScreenUtil.getInstance().setWidth(20)),
              decoration: BoxDecoration(
                  color: Colors.white, borderRadius: BorderRadius.circular(10)),
              child: Row(
                children: <Widget>[
                  Expanded(
                      child: Column(
                    children: <Widget>[
                      Container(
                        height: kMargin25,
                        width: 1,
                      ),
                      Row(
                        children: <Widget>[
                          Container(
                              margin: EdgeInsets.fromLTRB(0, 0, kMargin5, 0),
                              width: kMargin60,
                              height: kMargin60,
                              child: ClipRRect(
                                borderRadius:
                                    BorderRadius.circular(kMargin60 / 2),
                                child: item['user_avatar'] == null
                                    ? Image.asset('images/pic_default.png')
                                    : CachedNetworkImage(
                                        imageUrl: item['user_avatar']),
                              )),
                          Expanded(
                            child: Text(item['user_nickname'],
                                textDirection: TextDirection.ltr,
                                maxLines: 1,
                                softWrap: true,
                                overflow: TextOverflow.ellipsis,
                                style: TextStyle(
                                    fontSize: ScreenUtil.getInstance()
                                        .setSp(SMALL_FONT_SIZE))),
                          )
                        ],
                      ),
                      Container(
                        height: kMargin20,
                        width: 1,
                      ),
                      Expanded(
                        flex: 1,
                        child: Container(
                            margin: EdgeInsets.fromLTRB(0, 0, kMargin10, 0),
                            alignment: Alignment.topLeft,
                            child: Text(item['content'],
                                maxLines: 3,
                                textAlign: TextAlign.left,
                                softWrap: true,
                                overflow: TextOverflow.ellipsis,
                                style: TextStyle(
                                    fontSize: ScreenUtil.getInstance()
                                        .setSp(SMALL_FONT_SIZE)))),
                      )
                    ],
                  )),
                  item['have_img'].toString() == 'Y'
                      ? Expanded(
                          child: Container(
                              margin: EdgeInsets.fromLTRB(0, 0, kMargin5, 0),
                              child: ClipRRect(
                                borderRadius: BorderRadius.circular(kMargin20),
                                child: Image.network(
                                  Api.BaseUrl +
                                      'public/upload/' +
                                      item['img_arr'][0].replaceAll('\\', '/'),
                                ),
                              )))
                      : Container(),
                ],
              ))));
    }
    content = new Row(
        children: tiles //重点在这里，因为用编辑器写Column生成的children后面会跟一个<Widget>[]，
        //此时如果我们直接把生成的tiles放在<Widget>[]中是会报一个类型不匹配的错误，把<Widget>[]删了就可以了
        );
    return content;
  }

  showGoodsAttributes(BuildContext context) {
    showModalBottomSheet(
        context: context,
        backgroundColor: Colors.transparent,
        builder: (BuildContext context) {
          return StatefulBuilder(
            builder: (BuildContext context, setState) {
              return new Container(
                height: MediaQuery.of(context).size.height * 2 / 3,
                alignment: AlignmentDirectional.center,
                padding: EdgeInsets.fromLTRB(20, 0, 10, 10),
                decoration: BoxDecoration(
                    borderRadius: BorderRadius.only(
                      topLeft: Radius.circular(15),
                      topRight: Radius.circular(15),
                    ),
                    color: white),
                child: new Column(
                  children: <Widget>[
                    new Row(
                      mainAxisAlignment: MainAxisAlignment.end,
                      children: <Widget>[
                        GestureDetector(
                          onTap: () {
                            Navigator.of(context).pop();
                          },
                          child: Container(
                            width: 50,
                            color: white,
                            height: 50,
                            child: Image.asset('images/icon_close.png'),
                          ),
                        )
                      ],
                    ),
                    Expanded(
                      flex: 1,
                      child: SingleChildScrollView(
                        child: ChangeNotifierProvider.value(
                            value: skuProvider,
                            child: SkuDialog(
                              goods_name: goods_name,
                              initPrice: price.toString(),
                              img: gallery[0].img,
                            )),
                      ),
                    ),
                    Row(
                      children: <Widget>[
                        Expanded(
                          child: Text('数量',
                              maxLines: 1,
                              style: TextStyle(
                                  fontSize: ScreenUtil.getInstance()
                                      .setSp(SMALL_FONT_SIZE),
                                  color: black)),
                        ),
                        GestureDetector(
                          child: Icon(
                            Icons.remove,
                            color: black,
                            size: ScreenUtil.getInstance().setHeight(DP_30),
                          ),
                          onTap: () {
                            if (goods_num == 1) {
                              return;
                            }
                            goods_num--;
                            setState(() {});
                          },
                        ),
                        Container(
                          decoration: BoxDecoration(
                              borderRadius: BorderRadius.circular(2),
                              color: f0Color),
                          padding: EdgeInsets.fromLTRB(
                              ScreenUtil.getInstance().setHeight(DP_20),
                              2,
                              ScreenUtil.getInstance().setHeight(DP_20),
                              2),
                          margin: EdgeInsets.fromLTRB(
                              ScreenUtil.getInstance().setHeight(DP_10),
                              0,
                              ScreenUtil.getInstance().setHeight(DP_10),
                              0),
                          child: Text(
                            goods_num.toString(),
                            style: TextStyle(
                                fontSize: ScreenUtil.getInstance()
                                    .setSp(SMALL_FONT_SIZE),
                                color: Colors.black87),
                          ),
                        ),
                        GestureDetector(
                          child: Icon(
                            Icons.add,
                            size: ScreenUtil.getInstance().setHeight(DP_30),
                            color: black,
                          ),
                          onTap: () {
                            goods_num++;
                            setState(() {});
                          },
                        )
                      ],
                    ),
                    Container(
                      height: 10,
                    ),
                    Row(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: <Widget>[
                        new Container(
                          margin: EdgeInsets.fromLTRB(0, 10, 0, 10),
                          height: ScreenUtil.getInstance().setHeight(50),
                          decoration: new BoxDecoration(
                              color: Colors.orangeAccent,
                              borderRadius: BorderRadius.circular(
                                  ScreenUtil.getInstance().setHeight(5))),
                          child: new FlatButton(
                            child: new Padding(
                              padding: EdgeInsets.all(0.0),
                              child: new Text(
                                "加入购物车",
                                style: new TextStyle(
                                    color: Colors.white,
                                    fontSize: ScreenUtil.getInstance()
                                        .setSp(NORMAL_FONT_SIZE)),
                              ),
                            ),
                            onPressed: () {
                              // Navigator.of(context).pop();
                              if (hasSku) {
                                addToCar("");
                                return;
                              }
                              List<Map> skuMap = List();
                              List<Goods> list = goodsDetailsModel.goods;
                              for (int i = 0; i < list.length; i++) {
                                Map goodsSku = new Map();
                                goodsSku['attribute_id'] = list[i].attribute_id;
                                goodsSku['value'] = skuProvider
                                    .selectedSkuModel.sku
                                    .split(";")[i];
                                skuMap.add(goodsSku);
                              }
                              addToCar(json.encode(skuMap).toString());
                            },
                          ),
                        ),
                        new Container(
                          height: ScreenUtil.getInstance().setHeight(50),
                          margin: EdgeInsets.fromLTRB(20, 10, 0, 10),
                          decoration: new BoxDecoration(
                              color: mainColor,
                              borderRadius: BorderRadius.circular(
                                  ScreenUtil.getInstance().setHeight(5))),
                          child: new FlatButton(
                            child: new Padding(
                              padding: EdgeInsets.all(0.0),
                              child: new Text(
                                "立即下单",
                                style: new TextStyle(
                                    color: Colors.white,
                                    fontSize: ScreenUtil.getInstance()
                                        .setSp(NORMAL_FONT_SIZE)),
                              ),
                            ),
                            onPressed: () {
                              if (APPLIC.userInfoMap == null) {
                                Navigator.of(context).pushNamed('login');
                                return;
                              }
                              if (hasSku) {
                                Navigator.of(context)
                                    .push(MaterialPageRoute(builder: (context) {
                                  return BuyGoodsPage(
                                    old: '',
                                    goods_id: widget.goods_id,
                                    type: widget.type.toString(),
                                    goods_name: goods_name,
                                    goods_num: goods_num.toString(),
                                    save_money: save_money,
                                    goods_img: gallery[0].img,
                                    postage: "0",
                                    price: price.toString(),
                                    skuJson: "",
                                    id: widget.id,
                                    skuInfo: "无配置",
                                  );
                                }));
                                return;
                              }
                              List<Map> skuMap = List();
                              List<Goods> list = goodsDetailsModel.goods;
                              for (int i = 0; i < list.length; i++) {
                                Map goodsSku = new Map();
                                goodsSku['attribute_id'] = list[i].attribute_id;
                                goodsSku['value'] = skuProvider
                                    .selectedSkuModel.sku
                                    .split(";")[i];
                                skuMap.add(goodsSku);
                              }
                              // print(json.encode(skuMap).toString());
                              Navigator.of(context)
                                  .push(MaterialPageRoute(builder: (context) {
                                return BuyGoodsPage(
                                  old: '',
                                  goods_num: goods_num.toString(),
                                  goods_id: widget.goods_id,
                                  type: widget.type.toString(),
                                  goods_name: goods_name,
                                  save_money: save_money,
                                  goods_img: skuProvider.selectedSkuModel.img,
                                  price: skuProvider.selectedSkuModel.price
                                      .toString(),
                                  id: widget.id,
                                  postage: "0",
                                  skuJson: json.encode(skuMap).toString(),
                                  skuInfo: skuProvider.selectedSkuModel.sku,
                                );
                              }));
                              // Navigator.of(context).pop();
                            },
                          ),
                        )
                      ],
                    ),
                  ],
                ),
              );
            },
          );
        });
  }

  _onScroll(offset) {
    double alpha = offset / 50;
    if (alpha < 0) {
      alpha = 0;
    } else if (alpha > 1) {
      alpha = 1;
    }
    setState(() {
      appBarAlpha = alpha;
    });
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getString(TOKEN).then((value) {
      token = value;
      if (value == null) {
        Navigator.of(context).pushNamed('login');
        Toast.toast(context, msg: "请先登录后重试");
      } else {
        isCollect();
        getGoodsDetail();
        getCOMMENT();
      }
    });
    if (widget.img != null) {
      GalleryModel model = new GalleryModel(img: widget.img);
      gallery.add(model);
      count = 1;
    }

    goodsDetailsModel = GoodsDetailsModel.fromJson(skuMap);
    skuProvider = SkuProvider(goodsDetailsModel);
    var list =
        goodsDetailsModel.goods.map((item) => item.attribute_name).toList();
    skuProvider.selectedSku = "请选择\t${list.join("，")}";

    WidgetsBinding.instance.addObserver(this);
    APPLIC.eventBus.on<LoginEvent>().listen((event) {
      getString(TOKEN).then((value) {
        token = value;
        isCollect();
        getGoodsDetail();
        getCOMMENT();
      });
    });
  }

  @override
  void dispose() {
    super.dispose();
    WidgetsBinding.instance.removeObserver(this); //销毁观察者
  }

  isCollect() async {
    //是否收藏
    Map map = new Map.from({
      "sign_type": createSignType(Api.URL_GOODSCOLLECT_ISCOLLECT),
      'token': token,
      'goods_id': widget.goods_id.toString(),
    });
    print(map);
    Response<String> response = await HttpUtil()
        .post(Api.URL_GOODSCOLLECT_ISCOLLECT, data: getSign(map));
    Map userMap = json.decode(response.data);
    int code = userMap['code'];
    if (code == 1 && mounted) {
      setState(() {
        is_collect = userMap['data']['is_collect'];
      });
    }
  }

  collect() async {
    //收藏
    Map map = new Map.from({
      "sign_type": createSignType(Api.URL_GOODSCOLLECT),
      'token': token,
      'goods_id': widget.goods_id.toString(),
    });
    print(map);
    Response<String> response =
        await HttpUtil().post(Api.URL_GOODSCOLLECT, data: getSign(map));
    Map userMap = json.decode(response.data);
    int code = userMap['code'];
    if (code == 1 && mounted) {
      isCollect();
    }
  }

  cancelCollect() async {
    //取消收藏
    Map map = new Map.from({
      "sign_type": createSignType(Api.URL_GOODSCOLLECT_CANCEL),
      'token': token,
      'goods_id': widget.goods_id.toString(),
    });
    print(map);
    Response<String> response =
        await HttpUtil().post(Api.URL_GOODSCOLLECT_CANCEL, data: getSign(map));
    Map userMap = json.decode(response.data);
    int code = userMap['code'];
    if (code == 1 && mounted) {
      isCollect();
    }
  }

  addToCar(String attr) async {
    if (token == null) {
      Navigator.of(context).pushNamed('login');
      return;
    }
    //加入购物车
    if (attr != "") {
      print('有属性');
      // Map map = new Map.from({
      //   "sign_type": createSignType(Api.URL_SHOPCART_ADD),
      //   'token': token,
      //   'goods_id': widget.goods_id,
      //   'goods_num': goods_num,
      //   'goods_sku': attr
      // });
      // map = getSign(map);
      Map map = new Map.from({
        "sign_type": createSignType(Api.URL_SHOPCART_ADD),
        'token': token,
        'goods_id': widget.goods_id.toString(),
        'goods_num': goods_num.toString(),
        'goods_sku': attr.toString(),
      });
      print(map);
      Response<String> response =
          await HttpUtil().post(Api.URL_SHOPCART_ADD, data: getSign(map));
      Map userMap = json.decode(response.data);
      print(userMap);
      int code = userMap['code'];
      // Fluttertoast.showToast(msg: userMap['msg']);
      Toast.toast(context, msg: userMap['msg']);
      if (code == 1 && mounted) {}
    } else {
      print('没有属性');
      Map map = new Map.from({
        "sign_type": createSignType(Api.URL_SHOPCART_ADD),
        'token': token.toString(),
        'goods_id': widget.goods_id.toString(),
        'goods_num': goods_num.toString(),
      });
      Response<String> response =
          await HttpUtil().post(Api.URL_SHOPCART_ADD, data: getSign(map));
      Map userMap = json.decode(response.data);
      print(userMap);
      int code = userMap['code'];
      // Fluttertoast.showToast(msg: userMap['msg']);
      Toast.toast(context, msg: userMap['msg']);
      if (code == 1 && mounted) {
        APPLIC.eventBus.fire(LoginEvent());
      }
    }
  }

  getGoodsDetail() async {
    //商品详情
    Map map = new Map.from({
      "sign_type": createSignType(Api.URL_GOODS_MSG),
      'goods_id': widget.goods_id,
      "token": token
    });
    Response<String> response =
        await HttpUtil().post(Api.URL_GOODS_MSG, data: getSign(map));
    Map userMap = json.decode(response.data);
    print(userMap);
    int code = userMap['code'];
    if (code == 1 && mounted) {
      getRecommend(userMap['data']['goodsMsg']['cat_id'].toString());
      gallery.clear();
      if (userMap['data']['imglist'] == null ||
          (userMap['data']['imglist'] as List).length == 0) {
        GalleryModel model =
            new GalleryModel(img: userMap['data']['goodsMsg']['img']);
        gallery.add(model);
      } else {
        (userMap['data']['imglist'] as List).forEach((v) {
          gallery.add(new GalleryModel.fromJson(v));
        });
      }
      setState(() {
        count = gallery.length;
      });
      setState(() {
        html = userMap['data']['goodsMsg']['content'] == null
            ? ""
            : userMap['data']['goodsMsg']['content'];
        goods_name = userMap['data']['goodsMsg']['goods_name'];
        price = userMap['data']['goodsMsg']['price'];
        lable = userMap['data']['goodsMsg']['lable'];

        old_price = userMap['data']['goodsMsg']['old_price'];
        brand_name = userMap['data']['goodsMsg']['brand_name'];
        brand_id = userMap['data']['goodsMsg']['brand_id'].toString();
        save_money = userMap['data']['goodsMsg']['save_money'].toString();
        postage = userMap['data']['goodsMsg']['postage'].toString();
        getBrand(brand_id);
        if (userMap['data']['skulist'] != null &&
            (userMap['data']['skulist'] as List).length > 0) {
          setState(() {
            hasSku = false;
            for (Map item in userMap['data']['skulist']) {
              print(item);
            }
            skuMap['skus'] = userMap['data']['skulist'];
            skuMap['goods'] = userMap['data']['goodsMsg']['sku_arr'];
            goodsDetailsModel = GoodsDetailsModel.fromJson(skuMap);
            skuProvider = SkuProvider(goodsDetailsModel);
            var list = goodsDetailsModel.goods
                .map((item) => item.attribute_name)
                .toList();
            skuProvider.selectedSku = "请选择\t${list.join("，")}";
          });
        } else {
          setState(() {
            hasSku = true;
          });
        }
      });
    }
  }

  getCOMMENT() async {
    Map map = new Map.from({
      "sign_type": createSignType(Api.URL_GOODS_COMMENTLIST),
      'goods_id': widget.goods_id,
      'grade': '1',
    });
    Response<String> response =
        await HttpUtil().post(Api.URL_GOODS_COMMENTLIST, data: getSign(map));
    Map userMap = json.decode(response.data);
    print('商品评论');
    print(userMap);
    int code = userMap['code'];
    if (code == 1 && mounted) {
      setState(() {
        comments.clear();
        comments.addAll(userMap['data']['list']);
      });
    }
  }

  getRecommend(String cat_id) async {
    Map map = new Map.from({
      "sign_type": createSignType(Api.URL_GOODS_LIST),
      'cat_id': cat_id,
    });
    Response<String> response =
        await HttpUtil().post(Api.URL_GOODS_LIST, data: getSign(map));
    Map userMap = json.decode(response.data);
    // print('商品列表');
    // print(userMap);
    GoodsModelEntity goodsEntity = new GoodsModelEntity.fromJson(userMap);
    int code = userMap['code'];
    if (code == 1 && mounted) {
      setState(() {
        // _controller.finishRefresh();
        shopData = goodsEntity.data;
        // shopData.addAll(goodsEntity.data);
      });
    }
  }

  getBrand(String brand_id) async {
    Map map = new Map.from({
      "sign_type": createSignType(Api.URL_BRAND_MSG),
      'brand_id': brand_id,
    });
    print(getSign(map));
    Response<String> response =
        await HttpUtil().post(Api.URL_BRAND_MSG, data: getSign(map));
    Map userMap = json.decode(response.data);
    // print('品牌信息');
    // print(userMap);
    int code = userMap['code'];
    if (code == 1 && mounted) {
      setState(() {
        logo = userMap['data']['brandMsg']['logo'];
      });
    }
  }
}
